﻿Imports System.Collections.ObjectModel

Namespace Save

    ''' <summary>
    ''' 列アーカイブ生成クラス
    ''' </summary>
    ''' <remarks></remarks>
    Public Class ColumnArchiveFactory

        ''' <summary>
        ''' 列アーカイブを生成します
        ''' </summary>
        ''' <param name="instance"></param>
        ''' <param name="t"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function Create(instance As Object, t As Type) As ReadOnlyCollection(Of ColumnArchive)
            Dim lst As New List(Of ColumnArchive)

            For Each item As ColumnAttribute In (From el In ColumnAttributeReader.Read(t) Where el.IsSaveKey OrElse el.IsUpdatable)
                lst.Add(ColumnArchiveFactory.Create(instance, item))
            Next

            Return lst.AsReadOnly
        End Function

        ''' <summary>
        ''' 列アーカイブを生成します
        ''' </summary>
        ''' <param name="instance"></param>
        ''' <param name="col"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Private Shared Function Create(instance As Object, col As ColumnAttribute) As ColumnArchive
            Dim arch As New ColumnArchive

            arch.ColumnName = col.ColumnName
            arch.ArchiveValue = col.GetValue(instance)

            Return arch
        End Function

    End Class

End Namespace
